[][src]Crate async_session

Async HTTP sessions.

This crate provides a generic interface between cookie values and storage backends to create a concept of sessions. It provides an interface that can be used to encode and store sessions, and decode and load sessions generating cookies in the process.

Example

use async_session::{Session, SessionStore, MemoryStore};

// Init a new session store we can persist sessions to.
let mut store = MemoryStore::new();

// Create a new session.
let mut session = Session::new();
session.insert("user_id", 1)?;
assert!(session.data_changed());

// retrieve the cookie value to store in a session cookie
let cookie_value = store.store_session(session).await?.unwrap();

// Retrieve the session using the cookie.
let session = store.load_session(cookie_value).await?.unwrap();
assert_eq!(session.get::<usize>("user_id").unwrap(), 1);
assert!(!session.data_changed());

Re-exports

pub use base64;
pub use blake3;
pub use chrono;
pub use hmac;
pub use kv_log_macro as log;
pub use serde;
pub use serde_json;
pub use sha2;

Structs

CookieStore

A session store that serializes the entire session into a Cookie.

Error

The Error type, a wrapper around a dynamic error type.

MemoryStore

in-memory session store

Session

The main session type.

Traits

SessionStore

An async session backend.

Type Definitions

Result

An anyhow::Result with default return type of ()

Attribute Macros

async_trait